package com.happyscan138.makefun.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.happyscan138.makefun.BaseAdapter.my_join;
import com.happyscan138.makefun.R;
import com.happyscan138.makefun.View.RoundImageView;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by Administrator on 2016/12/8.
 */

public class myJoinAdapter extends BaseAdapter {
    Context mContext;
    List<my_join> mdata;

    public myJoinAdapter(Context mContext, List<my_join> mdata) {
        this.mContext = mContext;
        this.mdata = mdata;
    }

    @Override
    public int getCount() {
        return mdata.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int position, View view, ViewGroup viewGroup) {
        ViewHodler_myJoin viewHolder;
        if(view==null){
            viewHolder=new ViewHodler_myJoin();
            view=View.inflate(mContext, R.layout.my_join_item,null);
            viewHolder.myJoin_head=(RoundImageView) view.findViewById(R.id.my_join_head);
            viewHolder.myJoin_name=(TextView) view.findViewById(R.id.my_join_name);
            viewHolder.myJoin_time=(TextView) view.findViewById(R.id.my_join_time);
            viewHolder.myJoin_comment=(TextView) view.findViewById(R.id.my_join_comment);
            viewHolder.myJoin_image=(ImageView) view.findViewById(R.id.my_join_image);
 //           viewHolder.myJoin_nicheng=(TextView) view.findViewById(R.id.my_join_nicheng);
 //           viewHolder.myJoin_text=(TextView) view.findViewById(R.id.my_join_text);

            //将viewHolder与converView绑定
            view.setTag(viewHolder);
        }else {
            //如果存在converView，取出保存在converView中的viewHolder
            viewHolder=(ViewHodler_myJoin) view.getTag();
        }
        my_join bean=mdata.get(position);
        //通过viewHolder找到对应控件，避免每次通过findViewById找控件
        Picasso.with(mContext).load(bean.image).into(viewHolder.myJoin_head);
        viewHolder.myJoin_name.setText(bean.name);
        viewHolder.myJoin_time.setText(bean.time);
        viewHolder.myJoin_comment.setText(bean.comment);
        Picasso.with(mContext).load(bean.head).into(viewHolder.myJoin_image);
//        viewHolder.myJoin_nicheng.setText(bean.nicheng);
//        viewHolder.myJoin_text.setText(bean.text);

        return view;
    }
}

class ViewHodler_myJoin{
    public RoundImageView myJoin_head;
    public TextView myJoin_name;
    public TextView myJoin_time;
    public TextView myJoin_comment;
    public ImageView myJoin_image;
//    public TextView myJoin_nicheng;
//    public TextView myJoin_text;
        }